import 'package:core_package/core_package.dart';
import 'package:flutter/material.dart';

class TitleAlertWidget extends StatelessWidget {
  final String? title;
  final String? subTitle;
  final List<String>? actions;
  final Function(int index)? onTap;
  final EdgeInsets padding;
  final TextStyle? titleStyle;
  final TextStyle? subTitleStyle;
  final List<Color>? actionsColors;
  final List<Color>? actionsTitleColors;
  final double? subTitleTopHeight;
  final double? actionWidth;
  final double? actionHeight;
  final double? actionRadius;

  final double? actionSpace;

  TitleAlertWidget({
    this.title,
    this.subTitle,
    this.actions,
    this.onTap,
    this.padding = const EdgeInsets.all(20),
    this.titleStyle,
    this.subTitleStyle,
    this.actionsColors,
    this.subTitleTopHeight,
    this.actionHeight,
    this.actionSpace,
    this.actionWidth,
    this.actionRadius,
    this.actionsTitleColors,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: padding,
      child: Column(
        children: [
          titleWidget(),
          subTitleWidget(),
          Expanded(child: SizedBox()),
          buildAction(),
        ],
      ),
    );
  }

  Widget titleWidget() {
    if (title!.stringIsEmpty) return Container();
    return Text(
      title!,
      style: titleStyle ??
          TextStyle(
            color: MyColors.color_27_27_27,
            fontSize: MyFont.font16,
            fontWeight: MyFontWeight.bold,
          ),
    );
  }

  Widget subTitleWidget() {
    if (subTitle == null || subTitle!.stringIsEmpty) return Container();
    return Padding(
      padding: EdgeInsets.only(top: 10.px),
      child: Text(
        subTitle!,
        style: subTitleStyle ??
            TextStyle(
              color: MyColors.color_27_27_27,
              fontSize: MyFont.font14,
              fontWeight: MyFontWeight.regular,
            ),
      ),
    );
  }

  Widget buildAction() {
    if (actions == null || actionsColors == null) return Container();

    return Row(
      mainAxisSize: actions!.length == 1 ? MainAxisSize.min : MainAxisSize.max,
      children: List.generate(actions!.length, (index) {
        return Row(
          children: [
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                onTap?.call(index);
              },
              child: Container(
                width: actionWidth ?? 120.px,
                height: actionHeight ?? 40.px,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: actionsColors![index],
                  borderRadius: BorderRadius.circular(actionRadius ?? 4.px),
                ),
                child: Text(
                  actions![index],
                  style: TextStyle(
                    color: actionsTitleColors![index],
                    fontSize: SizeFill.setRx(16),
                  ),
                ),
              ),
            ),
            index != actions!.length - 1
                ? SizedBox(
                    width: actionSpace ?? 10.px,
                  )
                : Container(),
          ],
        );
      }),
    );
  }
}
